#pragma once

#include <functional>
#include "event_loop.h"

namespace uvpp
{
	class UVTimer
	{
	public:
		using TimeoutCallback = std::function<void (UVTimer*)>;
		using TimerStopComplete = std::function<void (UVTimer*)>;
		UVTimer(EventLoop* loop, uint64_t timeout, uint64_t repeat, TimeoutCallback callback);
		virtual ~UVTimer();

		void start();
		void stop(TimerStopComplete callback);
		void setRepeat(uint64_t ms);

	private:
		bool _started;
		uv_timer_t _timer;
		uint64_t _timeout;
		uint64_t _repeat;
		TimeoutCallback _onTimeoutCallback;
		TimerStopComplete _onStopCompleteCallback;

	private:
		void onTimeout();
		void onStopComplete();
	};
}
